package pl.textureStudio.model
{
	import pl.textureStudio.data.vo.StudioTextureVO;

	/**
	 * @author michalr
	 */
	public class StudioModel implements IStudioModel,IStudioModelHandlers
	{
		private static var _instance:IStudioModel;
		public var _currentEditedTexture:StudioTextureVO;
		public static var dataLoaded:Boolean;
		public static var dataReady:Boolean;
		// ...
		public var _dataLoadCount:uint;
		// ...
		private var showTexturesHandler:Function;
		private var editTextureHandler:Function;
		private var addNewTextureHandler:Function;
		private var closePanelHandler:Function;

		public static function getInstance():IStudioModel
		{
			if (_instance == null) _instance = new StudioModel();
			return _instance;
		}

		public function set currentEditedTexture( vo:StudioTextureVO ):void
		{
			_currentEditedTexture = vo;
		}

		public function get currentEditedTexture():StudioTextureVO
		{
			return _currentEditedTexture;
		}

		public function set dataLoadCount( val:uint ):void
		{
			_dataLoadCount = val;
		}

		public function get dataLoadCount():uint
		{
			return _dataLoadCount;
		}

		public function showTexturesList():void
		{
			if (showTexturesHandler != null) showTexturesHandler();
		}

		public function addShowTexturesListHandler( f:Function ):void
		{
			showTexturesHandler = f;
		}

		public function addEditTextureHandler( f:Function ):void
		{
			editTextureHandler = f;
		}

		public function addClosePanelHandler( f:Function ):void
		{
			closePanelHandler = f;
		}

		public function addTextureHandler( f:Function ):void
		{
			addNewTextureHandler = f;
		}

		public function addNewTexture():void
		{
			if (addNewTextureHandler != null) addNewTextureHandler();
		}

		public function editTextureByID( id:String ):void
		{
			if (editTextureHandler != null) editTextureHandler( id );
		}

		public function closePanel():void
		{
			if (closePanelHandler != null) closePanelHandler();
		}
	}
}
